package com.java110.api.listener.electric;

import com.alibaba.fastjson.JSONObject;
import com.java110.api.listener.AbstractServiceApiListener;
import com.java110.core.annotation.Java110Listener;
import com.java110.core.context.DataFlowContext;
import com.java110.core.event.service.api.ServiceDataFlowEvent;
import com.java110.dto.meterWater.WeDto;
import com.java110.intf.fee.IMeterWaterInnerServiceSMO;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.vo.ResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.List;

@Java110Listener("weRecordListListener")
public class WeRecordListListener extends AbstractServiceApiListener {

    @Autowired
    private IMeterWaterInnerServiceSMO meterWaterInnerServiceSMOImpl;

    private static Logger logger = LoggerFactory.getLogger(WeRecordListListener.class);
    @Override
    public String getServiceCode() {
        return "we.record.list";
    }

    @Override
    public HttpMethod getHttpMethod() {
        return HttpMethod.GET;
    }

    @Override
    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {

    }

    @Override
    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
        logger.debug("weRecordListListener : {}", event);
        ResultVo result = meterWaterInnerServiceSMOImpl.findWeRecords(reqJson.getString("mid"), reqJson.getInteger("page"), reqJson.getInteger("row"));
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(result.toString(), HttpStatus.OK);
        context.setResponseEntity(responseEntity);
    }


    @Override
    public int getOrder() {
        return 0;
    }
}
